package com.cloud.code.并发;

//死锁demo
public class DeadlockDemo {

    static User a = new User();
    static User b = new User();


    public static void main(String[] args) {

        new Thread(()->{
            System.out.println("enter a");

            synchronized (b){

                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (a){
                    System.out.println("a finish");
                }

            }
        }).start();

        new Thread(()->{
            System.out.println("enter b");

            synchronized (a){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (b){
                    System.out.println("b finish");
                }
            }
        }).start();
    }


}


class User {

    public User(){}
}
